<?php
require_once('../vendor/autoload.php');
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\WebDriverExpectedCondition;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverWait;
//$chromeDriverPath = "C:\Program Files\Google\Chrome\Application\chromedriver.exe"; // 这里需要填写你chromedriver的实际路径
//shell_exec($chromeDriverPath);
$options = new ChromeOptions();
//$options->addArguments(['--headless']);  //不出现浏览器
$options->addArguments(['--disable-blink-features=AutomationControlled']);
$options->addArguments(['--disable-extensions']);
$options->addArguments(['--disable-gpu']);
$options->addArguments(['--disable-infobars']);
$options->addArguments(['--disable-notifications']);
$options->addArguments(['--disable-popup-blocking']);
$options->addArguments(['--disable-web-security']);
$options->addArguments(['--ignore-certificate-errors']);
$options->addArguments(['--no-sandbox']);
$options->setExperimentalOption("useAutomationExtension", false);
$options->setExperimentalOption("excludeSwitches", ['enable-automation']);
//$options->addArguments(['--start-maximized']);
//chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
$options->addArguments(['--user-data-dir=/d/temp']);

$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
$driver = RemoteWebDriver::create('http://localhost:9515', $capabilities);
//$driver->setExperimentalOption('excludeSwitches', ['enable-automation', 'useAutomationExtension']);
//$driver->execute_cdp_cmd('Network.setUserAgentOverride', '{"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"}');

$driver->get('https://login.1688.com/member/signin.htm?done=https%3A%2F%2Fwww.1688.com%2F');
$script = 'Object.defineProperty(navigator, "webdriver", {get: () => undefined,});';
$driver->executeScript($script);
//$driver->setExperimentalOption('excludeSwitches', ['enable-automation']);
$element = $driver->findElement(WebDriverBy::id('fm-login-id'));
$element->sendKeys("yzs1013");
$element = $driver->findElement(WebDriverBy::id('fm-login-password'));
$element->sendKeys("~159456!aA");
$driver->findElement(WebDriverBy::className('password-login'))->click();
$wait = new WebDriverWait($driver, 10);
$driver->get("https://detail.1688.com/offer/652821208728.html?spm=a260j.12536015.ldmhbwv3.3.2c07700eABON7Q&&scm=1007.30832.181565.0&pvid=8cb1f471-ef86-44f7-b435-66a9f0ff31a0&object_id=652821208728&scm2=1007.30657.177495.0&pvid2=4a266251-20e9-4046-a9d2-2a229ef9dd76&trackInfo=1_652821208728_0.168056_0.0_0.0_0.0_670291644950-663463915951-662081208604-727184533153-771729966709-671802029727-644065490070-39457549779-547751496409-687493916108-645567856269-666790459925-730971668513-646617682476-730975264116-729972062457-702982997892-650036566973-738007081802-677184132981-724882812420-708172982844-727904802840-733724760930-734004382777-736353799565-638866564783-678638363505-728640238438-747973441011_null");
$cookies = $driver->manage()->getCookies();
$cookiestr="";
for($i=0;$i<count($cookies);$i++){
    $cookiestr.=$cookies[$i]->getName()."=".$cookies[$i]->getValue().";";
}
file_put_contents("d:/wwwroot/www/shop/yunshop/cookie/1688.txt",$cookiestr);
$driver->quit();
// 打印 Cookie 信息


